<!-- 服务管理列表 -->
<template>
  <div>

    <div>
      <myDivider name="设施设备"></myDivider>
      <div class="top">
        <div class="top-left">

          <el-select v-model="keyType" @change="SouSuo" filterable placeholder="选择设备类别" style="width: 262px;" clearable>
            <el-option v-for="item in categoryData" :key="item.number" :label="item.name" :value="item.number">
            </el-option>
          </el-select>
          <el-input class="Keyinput" v-model="keyName" placeholder="输入设备名称查询" clearable></el-input>
          <el-input class="Keyinput" v-model="keyNumber" placeholder="输入设备编号查询" clearable></el-input>
          <el-button class="searchForBtn" @click="SouSuo" type="primary" icon="el-icon-search">搜索</el-button>
        </div>

        <div class="top-right">
          <!-- <el-button size="mini" class="addBtn" type="primary" @click="goAdd" icon="el-icon-plus">新增</el-button> -->
          <el-button class="add" icon="el-icon-plus" type="primary"
            @click="$router.push('/facility/facilityAdd?type=add')">新增</el-button>
        </div>
      </div>
    </div>
    <!-- 表格列表 -->
    <div class="tableBox">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column align="center" prop="deviceName" label="设备名称" width="250">
        </el-table-column>
        <el-table-column align="center" prop="number" label="设备编号" width="150">
        </el-table-column>
        <el-table-column align="center" prop="model" label="规格型号" width="150">
        </el-table-column>
        <el-table-column align="center" prop="categoryName" label="设备类型">
        </el-table-column>
        <el-table-column align="center" prop="cost" label="资产原值">
        </el-table-column>
        <el-table-column align="center" prop="state" label="状态">
        </el-table-column>
        <el-table-column align="center" prop="description" label="备注">
        </el-table-column>

        <el-table-column align="center" label="操作" width="280">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="small"
              @click="echoValueForUpdate(scope.row)">编辑</el-button>
            <el-button type="danger" icon="el-icon-delete" size="small" @click="deleteById(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="display: flex;justify-content: center;">
      <!-- <el-pagination :current-page="pageNum" @current-change="PageChange" style="margin-top: 40px;" background
        layout="prev, pager, next" :total="total">
      </el-pagination> -->
      <myPagination :total="total" :pageNum="pageNum" @PageChange="PageChange" @pageSizeChange="pageSizeChange">
      </myPagination>
    </div>




  </div>
</template>

<script>
export default {

  data() {
    return {
      keyType: '',
      keyName: "",
      keyNumber: "",
      categoryData: {},
      tableData: [
      ],

      // 分页器
      pageNum: 1,
      total: null,
      pageSize: 10,
      userid: '',
    }
  },
  mounted() {
    this.userid = sessionStorage.getItem('soa_id')
  },
  activated() {
    this.keyType = ''
    this.keyName = ''
    this.keyNumber = ''
    this.getList()
    this.getCategoryData()

  },
  deactivated() {
  },
  methods: {
    pageSizeChange(e) {
      this.pageNum = 1
      this.pageSize = e
      this.getList()
    },

    PageChange(e) {
      this.pageNum = e
      this.getList()
    },

    // 搜索框
    SouSuo() {
      this.pageNum = 1
      this.getList();
    },
    async getList() {
      let params = {
        "categoryNumber": this.keyType, //机构类别编号
        "deviceName": this.keyName, //设备名称
        "number": this.keyNumber, //设备编号
        "pageNum": this.pageNum,
        "pageSize": this.pageSize
      }
      let res = await this.$api.facility.getFacilitiesList(params)
      console.log(res, 'ressss')
      if (res.list.length < 1 && this.pageNum != 1) { //判断，当搜索关键字有内容时，我直接点击分页，会造成关键词列表中没有某某页的数据，那么我就用第一页重新请求一次
        this.pageNum = 1
        this.getList()
        return
      }
      let arr = ['正常使用', '暂停使用']
      this.total = res.total
      this.tableData = []
      res.list.forEach(el => {
        this.tableData.push({
          id: el.id,
          deviceName: el.deviceName,
          number: el.number,
          model: el.model,
          categoryName: el.categoryName,
          cost: el.cost,
          state: el.state == 1 ? arr[0] : arr[1],
          description: el.description,
        })
      });
    },
    async getCategoryData() {
      let res = await this.$api.facility.getCategoryList()
      this.categoryData = res.data
    },
    async deleteById(row) {
      this.$confirm('是否删除该设备?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        var id = row.id;
        let res = await this.$api.facility.deleteById(id)
        if (res.code == 200) {
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.getList();
        } else {
          this.$message({
            message: res.message,
            type: "warning",
          });
        }
      }).catch(() => {
  
      });

    },
    echoValueForUpdate(row) {
      var id = row.id;
      this.$router.push({ path: '/facility/facilityAdd?type=detail', query: { id: id } })
    },






  },
}
</script>

<style lang="less" scoped>
.top {
  width: 100%;
  padding: 20px 30px;
  box-sizing: border-box;
  position: relative;

  .top-left {
    width: 60%;
    // padding: 20px 640px 20px 0px;
    box-sizing: border-box;
    position: relative;
    display: flex;
    align-items: center;
    // justify-content: flex-end;
    // float: left;

    .Keyinput {
      width: 200px;
      margin: 0 15px;
    }

    .searchForBtn {}

    .addBtn {}

  }

  .top-right {
    width: 35%;
    box-sizing: border-box;
    position: absolute;
    display: flex;
    justify-content: flex-end;
    right: 16px;
    top: 20px;

    .Keyinput {
      width: 200px;
      margin: 0 15px;
    }

    .searchForBtn {}

    .addBtn {}

  }
}


.tableBox {
  margin-top: 100px;

  /deep/ .el-table {
    .has-gutter {
      .is-leaf {}
    }
  }
}

.ok {
  width: 500px;
}

.eleList {
  width: 500px;

  .ele {
    margin: 5px 0;
    padding: 0 20px;
    box-sizing: border-box;
    width: 100%;
    height: 40px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    span {
      &:nth-child(2) {
        cursor: pointer;
      }
    }
  }
}



// .imgstyle {
//   width: 80px;
//   height: 80px;
//   display: flex;
//   flex-direction: column;
//   align-items: center;
//   border: 2px dashed black;
//   border-radius: 15px;
//   >i{
//     transform: scale(2);
//     margin: 15px 0;
//   }
// }</style>